package com.leyou.trade.utils;

/**
 * @ClassName : UserHolder  //类名
 * @Description :   //描述
 * @Author : qingfeng  //作者
 * @Date: 2020-09-22 19:24  //时间
 */
public class UserHolder {
    private static final ThreadLocal<Long> TL = new ThreadLocal<>();

    public static void setUser(Long userId){
        TL.set(userId);
    }

    public static Long getUser(){
        Long id = TL.get();
        if (id==null) {
            //不存在是返回默认值
            return 0L;
        }
        return id;
    }

    public static void removeUser(){
        TL.remove();
    }
}
